<template>
  <myDialog :isDialog="isShowXgmm" title="修改密码" :isFooter="true" @handleClose="$emit('drawerClose')">
    <template slot="content">
      <div class="passwordList">
        <el-form :model="pwdForm" status-icon :rules="rules" ref="pwdForm" label-width="80px">
          <el-form-item label="新密码" prop="oldPassword">
            <el-input  v-model="pwdForm.oldPassword" show-password autocomplete="off" placeholder="请输入新密码"/>
          </el-form-item>
          <el-form-item label="确认新密码" prop="newPassword">
            <el-input  v-model="pwdForm.newPassword" show-password autocomplete="off" placeholder="请再次输入您的新密码"/>
          </el-form-item>
          <el-form-item >
            <div class="tips">
              <span>*提示：</span>
              <span>首次登录需更改密码，初始密码由管理员在后台设定。</span>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </template>
    <template slot="footer">
      <div class="formBtnBox">
        <div class="editBtn"  @click="$emit('drawerClose')">取消</div>
        <div class="saveBtn  ml-4" @click="submitForm">确定</div>
      </div>
    </template>
  </myDialog>
</template>

<script>
import {resetPwdForNeedChange} from '@/api/login.js'
import {encrypt} from "@/utils/jsencrypt";
export default {
  props:{
    isShowXgmm:{
      type:Boolean,
      default:false,
    },
    rowData:{
      type:Object,
      default:()=>{}
    }
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.pwdForm.newPassword !== '') {
          this.$refs.ruleForm.validateField('newPassword');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.pwdForm.oldPassword) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    }
    return {
      pwdForm:{
        oldPassword:'',
        newPassword:''
      },
      formData: [
        {
          label:'',
          labelWidth:'0px',
          type:'slot',
          key:'password',
          slotName: "password",
          colLg:24,
        }
      ],
      rules: {
        oldPassword: [
          {validator: validatePass, trigger: 'blur' }
        ],
        newPassword: [
          {validator: validatePass2, trigger: 'blur'}
        ],
      }
    }
  },
  created(){
    if(this.rowData){
    }
  },
  mounted() {

  },
  methods: {
    submitForm(){
      this.pwdForm.newPassword = encrypt(this.pwdForm.newPassword)
      resetPwdForNeedChange({password:this.pwdForm.newPassword}).then((res)=>{
        if(res && res.code == 200){
          this.$message.success('操作成功！')
          this.$emit('drawerClose')
          this.$router.push({ path: '/index'})
        }
      })
    },
    // 添加保存传参
    recombinationFormData(param, callback) {
      param = {
        ...param,
      }
      callback({ ...param })
    },
    successAddChange(e) {
      this.$emit('drawerClose')
      this.$message.success('操作成功！')
    },
  },
}
</script>

<style lang="scss" scoped>
/deep/.el-dialog__body{
  padding:48px 88px !important;
  overflow: hidden !important;
}
/deep/.el-select  .el-input__inner{
  opacity:1;
}
/deep/.el-select .el-input .el-select__caret{
  display: block;
}
/deep/.el-form-item__label{
  color: #464d5a;
  font-family: "Alibaba PuHuiTi 3.0";
  font-weight: 400;
  font-size: 14px;
}
.passwordList{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  /deep/.el-form-item{
    margin-bottom: 24px;
  }
}
.tips{
  display: flex;
  align-items: center;
  >span{
    color: #464d5a;
    font-family: "Alibaba PuHuiTi 3.0";
    font-weight: 400;
    font-size: 12px;
    &:first-child{
      color: #ff4958;
    }
  }
}
</style>
